home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 15
/
Aminet 15 - Nov 1996.iso
/
Aminet
/
dev
/
gcc
/
ixemsdk.lha
/
man
/
cat3
/
gethostbyname.0
< prev
next >
Wrap
Text File
|
1996-09-02
|
7KB
|
138 lines
GETHOSTBYNAME(3) UNIX Programmer's Manual GETHOSTBYNAME(3)
NNAAMMEE
ggeetthhoossttbbyynnaammee, ggeetthhoossttbbyyaaddddrr, ggeetthhoosstteenntt, sseetthhoosstteenntt, eennddhhoosstteenntt, hheerrrroorr
- get network host entry
SSYYNNOOPPSSIISS
##iinncclluuddee <<nneettddbb..hh>>
eexxtteerrnn iinntt hh__eerrrrnnoo;;
_s_t_r_u_c_t _h_o_s_t_e_n_t _*
ggeetthhoossttbbyynnaammee(_c_o_n_s_t _c_h_a_r _*_n_a_m_e)
_s_t_r_u_c_t _h_o_s_t_e_n_t _*
ggeetthhoossttbbyyaaddddrr(_c_o_n_s_t _c_h_a_r _*_a_d_d_r, _i_n_t _l_e_n, _i_n_t _t_y_p_e)
_s_t_r_u_c_t _h_o_s_t_e_n_t _*
ggeetthhoosstteenntt(_v_o_i_d)
sseetthhoosstteenntt(_i_n_t _s_t_a_y_o_p_e_n)
eennddhhoosstteenntt(_v_o_i_d)
hheerrrroorr(_c_h_a_r _*_s_t_r_i_n_g)
DDEESSCCRRIIPPTTIIOONN
The ggeetthhoossttbbyynnaammee() and ggeetthhoossttbbyyaaddddrr() functions each return a pointer
to an object with the following structure describing an internet host
referenced by name or by address, respectively. This structure contains
either the information obtained from the name server, named(8), broken-
out fields from a line in _/_e_t_c_/_h_o_s_t_s, or database entries supplied by the
yp(8) system . If the local name server is not running these routines do
a lookup in _/_e_t_c_/_h_o_s_t_s.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
};
#define h_addr h_addr_list[0] /* address, for backward compatibility */
The members of this structure are:
_h___n_a_m_e Official name of the host.
_h___a_l_i_a_s_e_s A zero terminated array of alternate names for the host.
_h___a_d_d_r_t_y_p_e The type of address being returned; currently always
AF_INET.
_h___l_e_n_g_t_h The length, in bytes, of the address.
_h___a_d_d_r___l_i_s_t A zero terminated array of network addresses for the host.
Host addresses are returned in network byte order.
_h___a_d_d_r The first address in _h___a_d_d_r___l_i_s_t; this is for backward com-
patibility.
When using the nameserver, ggeetthhoossttbbyynnaammee() will search for
the named host in the current domain and its parents unless
the name ends in a dot. If the name contains no dot, and if
the environment variable ``HOSTALIASES'' contains the name
of an alias file, the alias file will first be searched for
an alias matching the input name. See hostname(7) for the
domain search procedure and the alias file format.
The sseetthhoosstteenntt() function may be used to request the use of
a connected TCP socket for queries. If the _s_t_a_y_o_p_e_n flag is
non-zero, this sets the option to send all queries to the
name server using TCP and to retain the connection after
each call to ggeetthhoossttbbyynnaammee() or ggeetthhoossttbbyyaaddddrr(). Otherwise,
queries are performed using UDP datagrams.
The eennddhhoosstteenntt() function closes the TCP connection.
FFIILLEESS
/etc/hosts
DDIIAAGGNNOOSSTTIICCSS
Error return status from ggeetthhoossttbbyynnaammee() and ggeetthhoossttbbyyaaddddrr() is indicated
by return of a null pointer. The external integer _h___e_r_r_n_o may then be
checked to see whether this is a temporary failure or an invalid or un-
known host. The routine hheerrrroorr() can be used to print an error message
describing the failure. If its argument _s_t_r_i_n_g is non-NULL, it is print-
ed, followed by a colon and a space. The error message is printed with a
trailing newline.
The variable _h___e_r_r_n_o can have the following values:
HOST_NOT_FOUND No such host is known.
TRY_AGAIN This is usually a temporary error and means that the lo-
cal server did not receive a response from an authorita-
tive server. A retry at some later time may succeed.
NO_RECOVERY Some unexpected server failure was encountered. This is
a non-recoverable error.
NO_DATA The requested name is valid but does not have an IP ad-
dress; this is not a temporary error. This means that
the name is known to the name server but there is no ad-
dress associated with this name. Another type of request
to the name server using this domain name will result in
an answer; for example, a mail-forwarder may be regis-
tered for this domain.
SSEEEE AALLSSOO
resolver(3), hosts(5), hostname(7), named(8)
CCAAVVEEAATT
The ggeetthhoosstteenntt() function is defined, and sseetthhoosstteenntt() and eennddhhoosstteenntt()
are redefined, when libc(3) is built to use only the routines to lookup
in _/_e_t_c_/_h_o_s_t_s and not the name server.
The ggeetthhoosstteenntt() function reads the next line of _/_e_t_c_/_h_o_s_t_s, opening the
file if necessary.
The sseetthhoosstteenntt() function opens and/or rewinds the file _/_e_t_c_/_h_o_s_t_s. If
the _s_t_a_y_o_p_e_n argument is non-zero, the file will not be closed after each
call to ggeetthhoossttbbyynnaammee() or ggeetthhoossttbbyyaaddddrr().
The eennddhhoosstteenntt() function closes the file.
HHIISSTTOORRYY
The hheerrrroorr() function appeared in 4.3BSD. The eennddhhoosstteenntt(),
ggeetthhoossttbbyyaaddddrr(), ggeetthhoossttbbyynnaammee(), ggeetthhoosstteenntt(), and sseetthhoosstteenntt() func-
tions appeared in 4.2BSD.
BBUUGGSS
These functions use static data storage; if the data is needed for future
use, it should be copied before any subsequent calls overwrite it. Only
the Internet address format is currently understood.
4.2 Berkeley Distribution April 19, 1994 3